﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.util {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import flash.geom.*;
    import flash.utils.*;
    import Classes.*;
    import Display.*;
    import flash.text.*;
    import flash.system.*;

    public class PerformanceTracker extends Sprite {

        private static const UPDATE_INTERVAL:Number = 1000;
        private static const TEXT_OFFSET:Point = new Point(250, -150);

        private static var m_randomRollCount:int;

        private var fontSize:Number;
        private var lastUpdate:Number;
        private var frameCount:Number;
        private var m_fpsText:TextField;
        private var m_memoryText:TextField;
        private var m_visibleObjects:TextField;
        private var m_transactionsText:TextField;

        public function PerformanceTracker(_arg1:Number=0xFFFFFF, _arg2:Number=12):void{
            var _local3:TextFormat = new TextFormat(null, _arg2, _arg1, true);
            this.m_fpsText = new StrokeTextField(0, 0.8);
            this.m_memoryText = new StrokeTextField(0, 0.8);
            this.m_visibleObjects = new StrokeTextField(0, 0.8);
            this.m_transactionsText = new StrokeTextField(0, 0.8);
            this.m_fpsText.setTextFormat(_local3);
            this.m_memoryText.setTextFormat(_local3);
            this.m_visibleObjects.setTextFormat(_local3);
            this.m_transactionsText.setTextFormat(_local3);
            this.m_transactionsText.autoSize = (this.m_visibleObjects.autoSize = (this.m_memoryText.autoSize = (this.m_fpsText.autoSize = TextFieldAutoSize.LEFT)));
            this.m_memoryText.defaultTextFormat = (this.m_fpsText.defaultTextFormat = (this.m_visibleObjects.defaultTextFormat = (this.m_transactionsText.defaultTextFormat = _local3)));
            this.m_transactionsText.selectable = (this.m_memoryText.selectable = (this.m_fpsText.selectable = false));
            this.m_transactionsText.mouseEnabled = (this.m_memoryText.mouseEnabled = (this.m_fpsText.mouseEnabled = false));
            this.updateText(this.frameCount);
            addChild(this.m_fpsText);
            addChild(this.m_memoryText);
            addChild(this.m_visibleObjects);
            addChild(this.m_transactionsText);
            addEventListener(Event.ADDED_TO_STAGE, this.setFPSUpdate);
            addEventListener(Event.REMOVED_FROM_STAGE, this.clearFPSUpdate);
        }
        public static function set rollCount(_arg1:int):void{
            m_randomRollCount = _arg1;
        }

        private function setFPSUpdate(_arg1:Event):void{
            addEventListener(Event.ENTER_FRAME, this.updateFPS);
            this.frameCount = 0;
            this.updateText(this.frameCount);
            this.lastUpdate = getTimer();
        }
        private function clearFPSUpdate(_arg1:Event):void{
            removeEventListener(Event.ENTER_FRAME, this.updateFPS);
        }
        private function updateFPS(_arg1:Event):void{
            var _local2:Number = getTimer();
            this.frameCount++;
            if (_local2 >= (this.lastUpdate + UPDATE_INTERVAL)){
                this.lastUpdate = _local2;
                this.updateText(this.frameCount);
                this.frameCount = 0;
            };
        }
        private function updateText(_arg1:Number):void{
            this.x = TEXT_OFFSET.x;
            this.y = (Global.stage.stageHeight + TEXT_OFFSET.y);
            var _local2:GameWorld = Global.world;
            var _local3:int = _local2.getNumObjects();
            var _local4:int = _local2.getNumVisibleObjects();
            var _local5:int = _local2.citySim.npcManager.walkerCount;
            var _local6:int = _local2.citySim.npcManager.getVisibleWalkerCount();
            var _local7:Number = Number(((System.totalMemory / 0x0400) / 0x0400));
            var _local8:int = TransactionManager.transactionQueueLength;
            var _local9:int = TransactionManager.maxQueued;
            this.m_fpsText.text = ((((((((((((((((((((_local8 + " / ") + _local9) + " | ") + _arg1) + " fps | ") + _local7.toFixed(2)) + " MB | ") + _local4) + "/") + _local3) + " objects visible") + " | ") + _local6) + "/") + _local5) + " walkers visible") + "\t(") + (Global.world.defCon + 1)) + ")") + (CloudManager.activated) ? "\tC" : "");
        }

    }
}//package Classes.util 
